package namespace.jcu.mobile.library.system;

import java.util.ArrayList;  
import android.app.Activity;  
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.ImageView;  
import android.widget.TextView;  
  
public class GridViewAdapter extends BaseAdapter  
{  
    private ArrayList<String> GridText;  
    private ArrayList<Integer> GridImage;  
    private Activity activity;  
  
    public GridViewAdapter(Activity activity,ArrayList<String> GridText, ArrayList<Integer> GridImage) {  
        super();  
        this.GridText = GridText;  
        this.GridImage = GridImage;  
        this.activity = activity;  
    }  
  
    public int getCount() {  
        return GridText.size();  
    }  
  
    public String getItem(int position) {  
        return GridText.get(position);  
    }  
  
    public long getItemId(int position) {  
        return 0;  
    }  
  
    public static class ViewHolder  
    {  
        public ImageView imageview;  
        public TextView imagelabel;  
    }  
  
    public View getView(int position, View convertView, ViewGroup parent) {  
        ViewHolder view;  
        LayoutInflater inflator = activity.getLayoutInflater();  
  
        if(convertView==null)  
        {  
            view = new ViewHolder();  
            convertView = inflator.inflate(R.layout.gridview_row, null);  
  
            view.imagelabel = (TextView) convertView.findViewById(R.id.textView1);  
            view.imageview = (ImageView) convertView.findViewById(R.id.imageView1);  
  
            convertView.setTag(view);  
        }  
        else  
        {  
            view = (ViewHolder) convertView.getTag();  
        }  
  
        view.imagelabel.setText(GridText.get(position));  
        view.imageview.setImageResource(GridImage.get(position));  
  
        return convertView;  
    }  
}  